import java.util.Arrays;

public class TestDemo1 {






//判断两个数组是否相同
public static void main(String[] args) {
    int[] array1={1,2,3,4,5,6,7,8,9,10};
    int[] array2={1,2,3,4,5,6,7,8,9,10};
    boolean ret = Arrays.equals(array1, array2);
    System.out.println(ret);
}





    /*//逆序数组
    public static void swap(int []array){
        for (int i = 0; i < array.length-1; i++) {
            int tmp=array[i];
            array[i]=array[i+1];
            array[i+1]=tmp;
        }
    }


    public static void reverse(int[] array){
        int i=0;
        int j= array.length;
        while (i<j){
            swap(array);
        }
    }

    public static void main(String[] args) {
        int []array={10,20,30,40};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }*/



    //冒泡排序
    public static void BubbleSort (int[] array){
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                }
            }

        }
    }
    //对数组进行排序
    public static void main2(String[] args) {
        int []array={10,40,20,30};
        System.out.println("排序前:"+ Arrays.toString(array));
        //Arrays.sort(array);
        BubbleSort(array);
        System.out.println("排序后:"+Arrays.toString(array));
        int ret =Arrays.binarySearch(array,10);
        System.out.println(ret);

    }




    //二分查找

    /**
     *
     * @param array
     * @param val
     * @return
     */
    public static int Binarysearch (int []array ,int val){
        int left=0;
        int right= array.length-1;
        while (left<=right){
            int mid=(left+right)/2;
            if(array[mid]<val){
                left=mid+1;
            } else if (array[mid] > val) {
                right=mid-1;
            }else {
                return mid;
            }
        }
        return -1;
    }

    public static void main1(String[] args) {
        int []array={10,20,30,40};
        int ret=Binarysearch(array,30);
        System.out.println(ret);
    }



    /**
     *
     * @param array  指定数组
     * @param val   查找的数据
     * @return   返回下标
     */
    public static int finval(int[] array,int val){
        for (int i = 0; i < array.length; i++) {
            if(array[i]==val){
                return i;
            }
        }
        return -1;
    }
}
